home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 16
/
Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso
/
Aminet
/
util
/
rexx
/
wac104.lha
/
WAC
next >
Wrap
Text File
|
1996-11-01
|
25KB
|
545 lines
/* What?! Another Calendar?! Version 1.04 */
/* Copyright © Michael Tanzer 1993, 1996 */
/* See additional notices in accompanying documentation */
blanks = 0 /* Number of blank lines at the top of the window. */
/* If you use a screen text font that is larger than */
/* 9 pixels in height, you may need to increase this */
/* value (by 1 or 2) for cosmetic purposes. */
/* Run WAC asynchronously */
w = getclip('WAC')
if w~=1 then do
call setclip('WAC',1)
address arexx 'WAC'
exit
end
call setclip('WAC')
/* Make sure the necessary functions are available */
if ~show('l','rexxsupport.library') then
call addlib('rexxsupport.library',0,-30)
if ~show('l','rexxarplib.library') then
call addlib('rexxarplib.library',0,-30)
signal on syntax
/* Insure only one copy of WAC is running */
if showlist('p','WAC') then do
address 'WAC' 'closewindow'
call delay(50)
end
if showlist('p','WACCTL') then call exit('WACCTL')
/* Set some rather important variables */
mode = 'M' /* Display mode */
cfgfile = 'S:WAC.config'
idcmp = 'closewindow+gadgetup+menupick'
flags = 'windowclose+windowdrag+windowdepth'
xchar = 8 /* Pixels / col */
ychar = 9 /* Pixels / row */
yoff = ychar*blanks /* Blank lines */
xminb = 20 /* 1st x pixel */
yminbm = 36+yoff /* 1st y (month) */
yminby = 45+yoff /* 1st y (year) */
hlsw = 0 /* No highlight */
heading = 'Mo Tu We Th Fr Sa Su'
dstring = ' 1 2 3 4 5 6 7 8 9 10 ' ||,
'11 12 13 14 15 16 17 18 19 20 ' ||,
'21 22 23 24 25 26 27 28 29 30 31'
/* Month mode */
wxm = 0 /* Window left */
wym = 0 /* Window top */
wwm = 200 /* Window width */
whm = 94+yoff /* Window height */
mlx = 7 /* MLESS left */
mly = 14+yoff /* MLESS top */
mrx = 24 /* MSTRG left */
mry = 14+yoff /* MSTRG top */
mrw = 74 /* MSTRG width */
mmx = 103 /* MMORE left */
mmy = 14+yoff /* MMORE top */
ylxm = 125 /* YLESS left */
ylym = 14+yoff /* YLESS top */
yrxm = 142 /* YSTRG left */
yrym = 14+yoff /* YSTRG top */
yrwm = 34 /* YSTRG width */
ymxm = 181 /* YMORE left */
ymym = 14+yoff /* YMORE top */
/* Year mode */
wxy = 0 /* Window left */
wyy = 0 /* Window top */
wwy = 568 /* Window width */
why = 346+yoff /* Window height */
ylxy = 251 /* YLESS left */
ylyy = 14+yoff /* YLESS top */
yrxy = 268 /* YSTRG left */
yryy = 14+yoff /* YSTRG top */
yrwy = 34 /* YSTRG width */
ymxy = 307 /* YMORE left */
ymyy = 14+yoff /* YMORE top */
/* Build some tables */
mo_days.1 = 31 /* Days in month */
mo_days.2 = 28
mo_days.3 = 31
mo_days.4 = 30
mo_days.5 = 31
mo_days.6 = 30
mo_days.7 = 31
mo_days.8 = 31
mo_days.9 = 30
mo_days.10 = 31
mo_days.11 = 30
mo_days.12 = 31
mo_prev.1 = 0 /* Days preceding month */
do month = 2 to 12
w = month-1
mo_prev.month = mo_prev.w+mo_days.w
end
mo_name.1 = 'January'
mo_name.2 = 'February'
mo_name.3 = 'March'
mo_name.4 = 'April'
mo_name.5 = 'May'
mo_name.6 = 'June'
mo_name.7 = 'July'
mo_name.8 = 'August'
mo_name.9 = 'September'
mo_name.10 = 'October'
mo_name.11 = 'November'
mo_name.12 = 'December'
mo_x.1 = 0 /* X offset for month */
mo_x.2 = 1*23*xchar
mo_x.3 = 2*23*xchar
mo_x.4 = 0
mo_x.5 = 1*23*xchar
mo_x.6 = 2*23*xchar
mo_x.7 = 0
mo_x.8 = 1*23*xchar
mo_x.9 = 2*23*xchar
mo_x.10 = 0
mo_x.11 = 1*23*xchar
mo_x.12 = 2*23*xchar
mo_y.1 = 0 /* Y offset for month */
mo_y.2 = 0
mo_y.3 = 0
mo_y.4 = 1*9*ychar
mo_y.5 = 1*9*ychar
mo_y.6 = 1*9*ychar
mo_y.7 = 2*9*ychar
mo_y.8 = 2*9*ychar
mo_y.9 = 2*9*ychar
mo_y.10 = 3*9*ychar
mo_y.11 = 3*9*ychar
mo_y.12 = 3*9*ychar
/* Read config file */
w = open('input',cfgfile,'r') /* Open config file as input */
if w=1 then do /* Proceed if file found */
w = readln('input') /* Read 1st record */
do while ~eof('input') /* Loop through rest of file */
interpret w /* Interpret this record */
w = readln('input') /* Read next record */
end
call close 'input' /* Close config file */
end
mode = upper(mode) /* Force upper case */
/* Set up host environment, window, etc. */
call reset /* Establish current date */
call openport('WAC') /* Open notify port */
address arexx "'call createhost(WACCTL,WAC)'"/* Open control port */
address command 'WAITFORPORT WACCTL' /* Note: fall through on error */
call openw /* Go open new window */
flags = flags'+activate' /* Adjust for mode changes */
/* Main control loop */
halt: do forever /* Top of main control loop */
signal on halt /* HI causes return to top */
trace 'b' /* Continue in spite of TS */
call waitpkt('WAC') /* Wait for some action */
pkt = getpkt('WAC') /* Retrieve packet */
if pkt=='00000000'x then iterate /* Caused by TS */
message = getarg(pkt) /* Retrieve message */
call reply(pkt,0) /* Acknowledge message */
action = upper(word(message,1)) /* Isolate 1st word of msg */
select /* Respond as required */
when action=='QUIT' then leave /* QUIT chosen from menu */
when action=='CLOSEWINDOW' then leave /* Window closed */
when action=='RESET' then do /* RESET chosen from menu */
call reset /* Re-establish current date */
call newyear /* Re-write year gadget */
call newmonth /* Re-write month gadget */
end /* RESET */
when action=='MLESS' then do /* MONTH LESS gadget */
month = month-1 /* Decrement month */
if month<1 then do /* If <January, */
month = 12 /* Use December */
if year>1900 then do /* If not minimum year, */
year = year-1 /* Decrement year */
call newyear /* Re-write year gadget */
end
end
call newmonth /* Re-write month gadget */
end /* MLESS */
when action=='MSTRG' then do /* MONTH STRING gadget */
w = substr(word(message,2),1,1) /* Get 1st char */
if w=='+' | w=='-' then do /* Relative reset */
call relative /* Go determine new date */
if result=0 then do /* Handle invalid request */
call newmonth /* Re-write month gadget */
iterate /* That's all */
end
call newmonth /* Re-write month gadget */
call newyear /* Re-write year gadget */
call mdates /* Fill in dates for month */
iterate /* All done */
end
reqmm = upper(word(message,2)) /* Get desired month */
if length(reqmm)>0 then do /* Got a desired month */
if datatype(reqmm,'w') & reqmm>=1 & reqmm<=12 then month = reqmm+0
else do w = 1 to 12 /* Find month in table */
if abbrev(upper(mo_name.w),reqmm) then do /* If match found, */
month = w /* Use new month */
leave /* Don't check others */
end
end
w = word(message,3) /* Got a date? */
if datatype(w,'w') & w>0 then do /* Yes, check it */
if w<=mo_days.month | (year//4=0 & month=2 & w=29) then do
day = w /* Set new day */
thisday = day /* Day becomes current */
thismonth = month /* Month becomes current */
thisyear = year /* year becomes current */
call removehl /* Remove highlight */
end
end
end
call newmonth /* Re-write month gadget */
end /* MSTRG */
when action=='MMORE' then do /* MONTH MORE gadget */
month = month+1 /* Increment month */
if month>12 then do /* If >December, */
month = 1 /* Use January */
if year<2099 then do /* If not maximum year, */
year = year+1 /* Increment year */
call newyear /* Re-write year gadget */
end
end
call newmonth /* Re-write month gadget */
end /* MMORE */
when action=='YLESS' then do /* YEAR LESS gadget */
if year>1900 then do /* If not minimum year, */
year = year-1 /* Decrement year */
call newyear /* Re-write year gadget */
end
end /* YLESS */
when action=='YSTRG' then do /* YEAR STRING gadget */
reqyy = word(message,2) /* Get desired year */
if datatype(reqyy,'w') & reqyy>=1900 & reqyy<=2099 then year = reqyy
call newyear /* Re-write year gadget */
end /* YSTRG */
when action=='YMORE' then do /* YEAR MORE gadget */
if year<2099 then do /* If not maximum year, */
year = year+1 /* Increment year */
call newyear /* Re-write year gadget */
end
end /* YMORE */
when action=='MMODE' then do /* MONTH MODE chosen from menu */
if mode=='Y' then do /* Check for year mode */
if words(message)>2 then do /* Check for window position */
wxy = word(message,2) /* Save year window x */
wyy = word(message,3) /* Save year window y */
end
call closewindow('WACCTL','continue')/* Close year window */
mode = 'M' /* Change mode to month */
call openw /* Go open new window */
iterate /* Bypass call to mdates */
end
end /* MMODE */
when action=='YMODE' then do /* YEAR MODE chosen from menu */
if mode=='M' then do /* Check for month mode */
if words(message)>2 then do /* Check for window position */
wxm = word(message,2) /* Save month window x */
wym = word(message,3) /* Save month window y */
end
call closewindow('WACCTL','continue')/* Close month window */
mode = 'Y' /* Change mode to year */
call openw /* Go open new window */
iterate /* Bypass call to ydates */
end
end /* YMODE */
when action=='SPREF' then do /* SAVE PREFS chosen from menu */
if words(message)>2 then do /* Check for window position */
if mode=='M' then do /* If in month mode, */
wxm = word(message,2) /* Save month window x */
wym = word(message,3) /* Save month window y */
end
else do /* If in year mode, */
wxy = word(message,2) /* Save year window x */
wyy = word(message,3) /* Save year window y */
end
end
w = statef(cfgfile) /* See if cfg file exists */
if w='' then call delete cfgfile /* If so, delete it */
call open 'output',cfgfile,'w' /* Open config file as output*/
if result then do /* Proceed if open ok */
w = 'mode =' mode /* Display mode */
call writeln 'output',w
w = 'wxm =' wxm /* Window left (month) */
call writeln 'output',w
w = 'wym =' wym /* Window top (month) */
call writeln 'output',w
w = 'wxy =' wxy /* Window left (year) */
call writeln 'output',w
w = 'wyy =' wyy /* Window top (year) */
call writeln 'output',w
call close 'output' /* Close output file */
msg = 'Preferences saved.' /* Build success message */
end
else msg = 'Unable to write\'cfgfile/* Build error message */
x = wxy /* Assume year mode */
y = wyy
if mode=='M' then do /* Handle month mode */
y = mym
if wxm+wwm<screencols('Workbench') then x = wxm
else x = wxm-40 /* Guard against overflow */
end
call postmsg(x,y,msg) /* Post the message */
call delay 100 /* Wait a couple seconds */
call postmsg() /* Clear the message */
drop x y msg /* Drop some variables */
iterate /* Bypass refresh */
end /* SPREF */
otherwise nop /* Ignore unknown actions */
end /* select */
if mode=='M' then call mdates /* Fill in dates for month */
else call ydates /* Fill in dates for year */
end /* Main control loop */
/* Clean up and get out */
syntax: signal off syntax /* Clear for next two calls */
call exit('WACCTL') /* Close window, remove host */
call closeport('WAC') /* Close notify port */
exit /* Ride off into the sunset */
/* Subroutines */
reset: /* Establish current date */
parse value date('s') with 1 thisyear +4 5 thismonth +2 7 thisday +2 .
thismonth = thismonth+0 /* Drop leading zero on month */
thisday = thisday+0 /* Drop leading zero on day */
year = thisyear /* Save current year */
month = thismonth /* Save current month */
day = thisday /* Save current day */
call removehl /* Current day may have changed*/
return
mdates: /* Fill in dates for month */
call getday /* Determine 1st day of month */
offset = result /* 0=Mo 1=Tu etc. */
days = mo_days.month /* Get & adjust days in month */
if year//4=0 & year>1900 & month=2 then days = days+1
dates = left(left(' ',offset*3)||substr(dstring,1,days*3-1),125)
do w = 21 to 105 by 21 /* Insert \s for new lines */
dates = overlay('\',dates,w)
end
w = left('\',blanks,'\') /* Adjust for large font */
text = w'\'heading'\'dates /* Add heading to date string */
if year=thisyear & month=thismonth then do /* Handle current month */
call windowtext('WACCTL',text) /* Write dates */
xmin = (offset+(thisday-1))//7*3*xchar+xminb
ymin = (offset+(thisday-1))%7*ychar+yminbm
xmax = xmin+xchar*2-1
ymax = ymin+ychar-1
call setdrmd('WACCTL','complement')
call rectfill('WACCTL',xmin,ymin,xmax,ymax)/* Highlight current date */
call setdrmd('WACCTL','jam1')
hlsw = 1 /* Indicate highlight */
end
else do /* Handle non-current month */
call removehl /* Remove highlight if any */
call windowtext('WACCTL',text) /* Write dates */
end
drop text dates /* Drop some variables */
return
ydates: /* Fill in dates for year */
savemonth = month /* Save current month */
text = left('\',blanks,'\') /* Clear, adjust for large font*/
do rx = 0 to 3 /* Build four rows */
line. = '' /* Clear all lines */
do month = rx*3+1 to rx*3+3 /* Build calendar for month */
call getday /* Determine 1st day */
offset = result /* 0 = Mo 1 = Tu etc. */
days = mo_days.month /* Get & adjust days */
if year//4=0 & year>1900 & month=2 then days = days+1
dates.month = left(left(' ',offset*3)||substr(dstring,1,days*3-1),125)
line.1 = line.1||centre(mo_name.month,20)' ' /* Month names */
line.2 = line.2||heading' ' /* Headings */
do lx = 3 to 8 /* Dates */
line.lx = line.lx||substr(dates.month,(lx-3)*21+1,20)' '
end
end
do lx = 1 to 8 /* Build row from lines */
text = text'\'substr(line.lx,1,66)
end
if rx<3 then text = text'\' /* Add space between rows */
end
if year=thisyear then do /* Handle current year */
month = thismonth /* Set for current month */
call windowtext('WACCTL',text) /* Write dates */
offset = getday() /* Get offset for the month */
xmin = (offset+(thisday-1))//7*3*xchar+xminb+mo_x.month
ymin = (offset+(thisday-1))%7*ychar+yminby+mo_y.month
xmax = xmin+xchar*2-1
ymax = ymin+ychar-1
call setdrmd('WACCTL','complement')
call rectfill('WACCTL',xmin,ymin,xmax,ymax)/* Highlight current date */
call setdrmd('WACCTL','jam1')
hlsw = 1 /* Indicate highlight */
end
else do /* Handle non-current year */
call removehl /* Remove highlight if any */
call windowtext('WACCTL',text) /* Write dates */
end
month = savemonth /* Restore current month */
drop text dates. line. rx lx savemonth /* Drop some variables */
return
openw: /* Open a window */
if mode=='M' then do /* Set for month */
w = screencols('Workbench')
if wxm+wwm<=w then wx = wxm
else wx = w-wwm
w = screenrows('Workbench')
if wym+whm<=w then wy = wym
else wy = w-whm
ww = wwm
wh = whm
ylx = ylxm
yly = ylym
yrx = yrxm
yry = yrym
yrw = yrwm
ymx = ymxm
ymy = ymym
end
else do /* Set for year */
w = screencols('Workbench')
if wxy+wwy<=w then wx = wxy
else wx = w-wwy
w = screenrows('Workbench')
if wyy+why<=w then wy = wyy
else wy = w-why
ww = wwy
wh = why
ylx = ylxy
yly = ylyy
yrx = yrxy
yry = yryy
yrw = yrwy
ymx = ymxy
ymy = ymyy
end
call openwindow('WACCTL',wx,wy,ww,wh,idcmp,flags,'WAC')
call addmenu('WACCTL','WAC ')
call additem('WACCTL','Reset ','reset')
call additem('WACCTL','Mode','mode')
call addsubitem('WACCTL',' Month','mmode %f %e',,-1)
call addsubitem('WACCTL',' Year ','ymode %f %e',,-1)
call additem('WACCTL','Save prefs ','spref %f %e')
call additem('WACCTL','Quit ','quit')
call addgadget('WACCTL',ylx,yly,'yless','<','yless')
call addgadget('WACCTL',yrx,yry,'ystrg',year,'ystrg %g',yrw)
call addgadget('WACCTL',ymx,ymy,'yless','>','ymore')
if mode=='Y' then do
call setitem('WACCTL',0,1,1,'on')
call ydates /* Fill in dates for year */
return
end
call addgadget('WACCTL',mlx,mly,'mless','<','mless')
w = left(mo_name.month,9)
call addgadget('WACCTL',mrx,mry,'mstrg',w,'mstrg %g',mrw)
call addgadget('WACCTL',mmx,mmy,'mmore','>','mmore')
call setitem('WACCTL',0,1,0,'on')
call mdates /* Fill in dates for month */
return
newmonth: /* Re-write month gadget */
if mode=='Y' then return /* If year mode just return */
call removegadget('WACCTL','mstrg') /* Remove old gadget */
w = left(mo_name.month,9)
call addgadget('WACCTL',mrx,mry,'mstrg',w,'mstrg %g',mrw)
return
newyear: /* Re-write year gadget */
call removegadget('WACCTL','ystrg') /* Remove old gadget */
call addgadget('WACCTL',yrx,yry,'ystrg',year,'ystrg %g',yrw)
return
removehl: /* Remove highlight */
if ~hlsw then return /* If no highlight just return */
call setapen('WACCTL',0)
call rectfill('WACCTL',xmin,ymin,xmax,ymax) /* Remove highlight */
hlsw = 0 /* Mark the trail */
return
getday: /* Get first day of month */
w = year-1900
days = w+(w-1)%4+mo_prev.month
if year//4=0 & year>1900 & month>2 then days = days+1
return days//7
relative: /* Handle relative date change */
count = upper(word(message,2)) /* Get desired count */
period = upper(word(message,3)) /* Get desired period */
if ~datatype(count,'w') then return 0 /* Return if count invalid */
if words(period)=0 then period = 'DAYS' /* Default period is DAYS */
saveyear = thisyear /* Save current settings */
savemonth = thismonth
saveday = thisday
select
when abbrev('DAYS',period) then do
w = thisyear||right(thismonth,2,'0')||right(thisday,2,'0')
w = date('s',date('i',w,'s')+count,'i')
thisyear = substr(w,1,4) /* Get new year */
thismonth = substr(w,5,2)+0 /* Get new month */
thisday = substr(w,7)+0 /* Get new day */
end
when abbrev('WEEKS',period) then do
w = thisyear||right(thismonth,2,'0')||right(thisday,2,'0')
w = date('s',date('i',w,'s')+count*7,'i')
thisyear = substr(w,1,4) /* Get new year */
thismonth = substr(w,5,2)+0 /* Get new month */
thisday = substr(w,7)+0 /* Get new day */
end
when abbrev('MONTHS',period) then do
w = thisyear*12+thismonth+count /* Get total months */
thisyear = (w-1)%12 /* Get new year */
thismonth = w//12 /* Get new month */
if thismonth=0 then thismonth = 12
end
when abbrev('YEARS',period) then ,
thisyear = thisyear+count /* Get new year */
otherwise return 0
end
if thisyear<1900 | thisyear>2099 then do/* Handle invalid setting */
thisyear = saveyear /* Restore saved values */
thismonth = savemonth
thisday = saveday
return 0
end
year = thisyear /* Save current year */
month = thismonth /* Save current month */
day = thisday /* Save current day */
call removehl /* Current day has changed */
return 1